﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ecomerci
{
    public partial class preferences : Form
    {
        public string databasePath { get; set; }
        public string invoicePath { get; set; }
        public string salesOverviewPath { get; set; }

        applicationLogic logic = new applicationLogic();
        FolderBrowserDialog folderDialog = new FolderBrowserDialog();

        public preferences()
        {
            InitializeComponent();
            btSelectDatabasePath.Enabled = false;
            logic.getInvoicePath();
            txInvoicePath.Text = logic.getInvoicePath();
            txSalesOverviewPath.Text = logic.getSalesOverviewPath();
            invoicePath = txInvoicePath.Text.ToString();
            salesOverviewPath = txSalesOverviewPath.Text.ToString();
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void btSelectDatabasePath_Click(object sender, EventArgs e)
        {
            folderDialog.ShowDialog();
            if (folderDialog.SelectedPath != string.Empty)
            {
                databasePath = folderDialog.SelectedPath.ToString();
            }
        }

        private void btSelectInvoicePath_Click(object sender, EventArgs e)
        {
            DialogResult folderDialogResult = folderDialog.ShowDialog();
            if(folderDialogResult == DialogResult.OK)
            {
                txInvoicePath.Text = folderDialog.SelectedPath.ToString();
                invoicePath = txInvoicePath.Text.ToString();
            }
        }

        private void btSelectSalesOverviewPath_Click(object sender, EventArgs e)
        {
            DialogResult folderDialogResult = folderDialog.ShowDialog();
            if (folderDialogResult == DialogResult.OK)
            {
                txSalesOverviewPath.Text = folderDialog.SelectedPath.ToString();
                salesOverviewPath = txSalesOverviewPath.Text.ToString();
            }
        }

        private void btApply_Click(object sender, EventArgs e)
        {
            try
            {
                logic.setInvoicePath(txInvoicePath.Text.ToString());
                logic.setSalesOverviewPath(txSalesOverviewPath.Text.ToString());
            }
            catch (Exception ex)
            {
                logic.showException(ex);
            }
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
